import request from './request'

/**
 * 消息相关API
 */

// 用户消息API
export const messageApi = {
  // 获取用户消息列表
  getUserMessages(params = {}) {
    return request({
      url: '/user/messages/',
      method: 'get',
      params
    })
  },

  // 获取单条消息详情
  getMessageDetail(id) {
    return request({
      url: `/user/messages/${id}/`,
      method: 'get'
    })
  },

  // 标记消息为已读
  markMessageRead(id) {
    return request({
      url: `/user/messages/${id}/mark_read/`,
      method: 'post'
    })
  },

  // 批量标记所有消息为已读
  markAllMessagesRead() {
    return request({
      url: '/user/messages/mark_all_read/',
      method: 'post'
    })
  },

  // 获取未读消息数量
  getUnreadCount() {
    return request({
      url: '/user/messages/unread_count/',
      method: 'get'
    })
  }
}

// 管理员消息API
export const adminMessageApi = {
  // 获取消息列表
  getMessages(params = {}) {
    return request({
      url: '/admin/messages/',
      method: 'get',
      params
    })
  },

  // 获取单条消息详情
  getMessageDetail(id) {
    return request({
      url: `/admin/messages/${id}/`,
      method: 'get'
    })
  },

  // 创建消息
  createMessage(data) {
    return request({
      url: '/admin/messages/',
      method: 'post',
      data
    })
  },

  // 更新消息
  updateMessage(id, data) {
    return request({
      url: `/admin/messages/${id}/`,
      method: 'put',
      data
    })
  },

  // 删除消息
  deleteMessage(id) {
    return request({
      url: `/admin/messages/${id}/`,
      method: 'delete'
    })
  }
}